import bpy

# 获取当前活跃的对象
obj = bpy.context.active_object

# 获取顶点组
vertex_group_name = "vertex1"
vertex_group = obj.vertex_groups.get(vertex_group_name)

if vertex_group is None:
    print(f"No vertex group named '{vertex_group_name}' found.")
else:
    # 获取网格数据
    mesh = obj.data

    # 创建一个列表来保存顶点信息
    vertices_with_bool = []

    # 遍历所有的顶点
    for vertex in mesh.vertices:
        # 初始化布尔值，默认为 False
        bool_value = False

        # 检查顶点是否属于指定的顶点组
        for group_element in vertex.groups:
            if group_element.group == vertex_group.index and group_element.weight > 0.0:
                bool_value = True
                break

        # 添加顶点坐标和布尔值到列表
        vertices_with_bool.append((vertex.co, bool_value))

    # 输出顶点信息
    for vertex_info in vertices_with_bool:
        print(f"Vertex Position: {vertex_info[0]}, In Vertex Group: {vertex_info[1]}")


    def write_vertices_to_csv(filename, vertices_with_bool):
        with open(filename, 'w') as file:
            for vertex_info in vertices_with_bool:
                file.write(f"{vertex_info[0].x},{vertex_info[0].y},{vertex_info[0].z},{int(vertex_info[1])}\n")


    # ... (之前的代码保持不变) ...

    # 输出顶点信息到 CSV 文件
    write_vertices_to_csv('vertices_with_bool.csv', vertices_with_bool)